package test4;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class UploadServer {

    public static void main(String[] args) {
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        OutputStream os = null;
        try {
            //创建服务器对象
            ServerSocket serverSocket = new ServerSocket(9898);
            //监听客户端
            Socket socket = serverSocket.accept();
            //图片视频音频用字节流
             bis = new BufferedInputStream(socket.getInputStream());
            //读完图片文件之后要把它写进硬盘
             bos = new BufferedOutputStream(new FileOutputStream("D:\\backup\\ab.mp3"));
            byte[] buf = new byte[1024];
            int len = -1;
            while ((len = bis.read(buf))!=-1){
                bos.write(buf,0,len);
            }
            bos.flush();
            os = socket.getOutputStream();
            os.write("文件上传成功!".getBytes());
            os.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bis.close();
                bos.close();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


}
